
#include "main.h"

static const char *TAG = "led_callback";


void led_callback(const blinker_widget_param_val_t *val)
{
    ESP_LOGI(TAG, "led state: %s", val->s);

    if (strcmp(val->s, "on") == 0) {
        ledOpen();
    } else {
        ledClose();
    }

    int power = 0;
    if (ESP_OK == adc_read(&power)) {
        ESP_LOGI(TAG, "adc read: %d\r\n", power);
    }

    char pwoerStr[10] = {0};
    sprintf(pwoerStr, "%s:%d", "pod", power);
    cJSON *param1 = cJSON_CreateObject();
    blinker_widget_text(param1, pwoerStr);
    blinker_widget_print(TEXT_POWER, param1);
    cJSON_Delete(param1);

    esp_power_consumption_info(false);
    cJSON *param = cJSON_CreateObject();
    blinker_widget_switch(param, val->s);
    blinker_widget_print(BUTTON_LED, param);
    cJSON_Delete(param);
}
